package com.qst.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qst.common.annotation.Log;
import com.qst.common.core.controller.BaseController;
import com.qst.common.core.domain.AjaxResult;
import com.qst.common.enums.BusinessType;
import com.qst.system.domain.LevelReward;
import com.qst.system.domain.vo.LevelRewardVo;
import com.qst.system.service.ILevelRewardService;
import com.qst.common.core.page.TableDataInfo;
import com.qst.common.utils.poi.ExcelUtil;

/**
 * 等级奖励Controller
 * 
 * @author linzhe
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/system/reward")
public class LevelRewardController extends BaseController
{
    @Autowired
    private ILevelRewardService levelRewardService;

    /**
     * 查询等级奖励列表
     */
    @PreAuthorize("@ss.hasPermi('system:reward:list')")
    @GetMapping("/list")
    public TableDataInfo list(LevelReward levelReward)
    {
        startPage();
        List<LevelRewardVo> list = levelRewardService.selectLevelRewardList(levelReward);
        return getDataTable(list);
    }

    /**
     * 导出等级奖励列表
     */
    @PreAuthorize("@ss.hasPermi('system:reward:export')")
    @Log(title = "等级奖励", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HttpServletResponse response, LevelReward levelReward)
    {
        List<LevelRewardVo> list = levelRewardService.selectLevelRewardList(levelReward);
        ExcelUtil<LevelRewardVo> util = new ExcelUtil<LevelRewardVo>(LevelRewardVo.class);
        return util.exportExcel(list, "等级奖励数据");
    }

    /**
     * 获取等级奖励详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:reward:query')")
    @GetMapping(value = "/{rewardId}")
    public AjaxResult getInfo(@PathVariable("rewardId") Long rewardId)
    {
        return AjaxResult.success(levelRewardService.selectLevelRewardById(rewardId));
    }

    /**
     * 新增等级奖励
     */
    @PreAuthorize("@ss.hasPermi('system:reward:add')")
    @Log(title = "等级奖励", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LevelReward levelReward)
    {
        return toAjax(levelRewardService.insertLevelReward(levelReward));
    }

    /**
     * 修改等级奖励
     */
    @PreAuthorize("@ss.hasPermi('system:reward:edit')")
    @Log(title = "等级奖励", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LevelReward levelReward)
    {
        return toAjax(levelRewardService.updateLevelReward(levelReward));
    }

    /**
     * 删除等级奖励
     */
    @PreAuthorize("@ss.hasPermi('system:reward:remove')")
    @Log(title = "等级奖励", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rewardIds}")
    public AjaxResult remove(@PathVariable Long[] rewardIds)
    {
        return toAjax(levelRewardService.deleteLevelRewardByIds(rewardIds));
    }
}